/*
* Copyright 2004-2005 mbsx@seznam.cz
* All Rights Reserved.
*/
using System;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Text;

namespace DeskNotes
{
	/// <summary>
	/// Summary description for ArchivedNoteNode.
	/// </summary>
	public class ArchivedNoteNode : DeskNotesTreeNode, IPrintableNote
	{
		//internal long id;
		
		private string noteText;
		private DateTime archiveTime = DateTime.Now;
        private DateTime lastModificationTime = DateTime.MinValue;
        private Font font = null;
		private Color textColor = Color.Black;
		private Color backColor = Color.White;
		private static DateTimeFormatInfo myDTFI = System.Windows.Forms.Application.CurrentCulture.DateTimeFormat;
			//System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat;

		//internal Rectangle position = Rectangle.Empty;
		/// <summary>
		/// Default constructor used to create node during drag&drop
		/// </summary>
		public ArchivedNoteNode()
		{
			type = DeskNotesTreeNode.NOTE;
		}

        /// <summary>
        /// Creates archived note node with following params
        /// </summary>
        /// <param name="text">Rtf formatted text of DeskNote being archived</param>
        /// <param name="id">ID</param>
		public ArchivedNoteNode(string text, long id)
		{
			this.id = id;
			this.Text = RtfConverter.Text(text);
			this.noteText = text;
			this.ImageIndex = ArchiveForm.NOTE_IMAGE;
			this.SelectedImageIndex = ArchiveForm.NOTE_IMAGE;
			type = DeskNotesTreeNode.NOTE;
		}

        /// <summary>
        /// Plain text for archived note displayed in tree nodes
        /// </summary>
		internal new string Text
		{
			set
			{
				string text = (string)value;
				if (text.Length > 25)
					text = text.Substring(0,22)+"...";
				base.Text = text.Replace("\n", " ");
			}
			get
			{
				return base.Text;
			}
		}
		/// <summary>
		/// Create archived desknote from note just being archived from desktop.
		/// archive id is not set 
		/// </summary>
		/// <param name="note">DeskNote being archived</param>
		public ArchivedNoteNode(Note note)
		{
			this.Text = RtfConverter.Text( note.Text);
			this.noteText = note.Text;
            this.LastModificationTime = note.LastModificationTime;
			this.Font = note.ExtraFont;
			this.backColor = note.BackgroundColor;
			this.textColor = note.TextColor;
			this.ImageIndex = ArchiveForm.NOTE_IMAGE;
			this.SelectedImageIndex = ArchiveForm.NOTE_IMAGE;
		}

		internal string NoteText
		{
			set
			{
				this.noteText = value;
				this.Text = RtfConverter.Text(value);
			}
			get 
			{
				return noteText;
			}
		}

		internal Font Font
		{
			set 
			{
				this.font = value;
			}
			get 
			{
				return this.font;
			}
		}

		internal Color PanelBackColor
		{
			get 
			{
				return backColor;
			}
			set 
			{
				backColor = value;
			}
		}

		internal Color PanelTextColor
		{
			get 
			{
				return textColor;
			}
			set 
			{
				textColor = value;
			}
		}

			internal DateTime ArchivedTime 
		{
			get 
			{
				return archiveTime;
			}
			set 
			{
				archiveTime = value;
			}
		}

        internal DateTime LastModificationTime
        {
            get { return lastModificationTime; }
            set { lastModificationTime = value; }
        }

        internal string LastModificationTimeText
        {
            get
            {
                return lastModificationTime.ToString(myDTFI.ShortDatePattern) + " " + lastModificationTime.ToString(myDTFI.ShortTimePattern);
            }
        }

		internal string ArchivedTimeText 
		{
			get 
			{
				return archiveTime.ToString(myDTFI.ShortDatePattern) + " " + archiveTime.ToString(myDTFI.ShortTimePattern);
			}
		}
		#region IPrintableNote Members

		public string HeaderText
		{
			get
			{
				StringBuilder header = new StringBuilder(150);
				if (null != this.Parent)
					header.Append(this.Parent.FullPath);
				else 
					header.Append(this.FullPath);
				header.Append("\n");
				header.Append(string.Format(MainResource.GetString("ARCHIVED_ON"), this.ArchivedTimeText));
				return header.ToString();
			}
		}

		public bool HasHeader
		{
			get
			{
				return true;
			}
		}

		public System.Drawing.StringAlignment HeaderAlign
		{
			get
			{
				return System.Drawing.StringAlignment.Near;
			}
		}

		public Font GetOwnFont
		{
			get
			{
				return this.font;
			}
		}

		public string BodyText
		{
			get
			{
				return RtfConverter.Text(this.noteText);
			}
		}

		#endregion
	}

}
